package com.sf.dlb.controller;


import com.sf.dlb.bean.VisitorInfoBean;
import com.sf.dlb.constant.ResponseConstant;
import com.sf.dlb.service.VisitorInfoService;
import com.sf.dlb.utils.GsonUtils;
import com.sf.dlb.utils.ResultVOUtil;
import com.sf.dlb.vo.ResultVO;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 游客
 * Created by jing.tan on 2018/12/10.
 */
@RestController
@RequestMapping(value = "/v1/visitor")
public class VisitorInfoController {
    private static Logger logger = LoggerFactory.getLogger(VisitorInfoController.class);
    @Autowired
    private VisitorInfoService visitorInfoService;


    /**
     * 创建游客
     * @returns
     */
    @PostMapping(value = "/create")
    @ResponseBody
    public Object createVisitor(@RequestBody VisitorInfoBean visitorInfoBean) {
        logger.info("createVisitor start == "+GsonUtils.getInstance().toJson(visitorInfoBean));
        if(StringUtils.isBlank(visitorInfoBean.getDeviceNumber())){
            return ResultVOUtil.error(ResponseConstant.ERROR,"设备号不能为空");
        }
        ResultVO resultVO=visitorInfoService.createVisitorInfo(visitorInfoBean.getDeviceNumber(),visitorInfoBean.getDeviceType());
        logger.info("createVisitor end == "+ GsonUtils.getInstance().toJson(resultVO));
        return ResultVOUtil.success(resultVO);
    }
}
